const mutations = {
    addCart(state,{sku,title,price,image}){
        let isHas = state.car.some(item=>{
            if(item.sku ==sku){
                item.num++;
                return true;
            }else{
                return false;
            }
        })
        if(!isHas){            
            state.car.push({sku,title,price,image,num:1})
        } 
        console.log(state.car)
    },
    subtract(state,{sku}){
        var len =state.car.length ;
        for(var i =0;i<len;i++){
            if(state.car[i].num > 1){
                if(state.car[i].sku==sku){
                    state.car[i].num --;
                    
                }
            }
            
        }
    },
    augment(state,{sku}){
        var len =state.car.length ;
        for(var i =0;i<len;i++){
            if(state.car[i].sku==sku){
                state.car[i].num ++;
            }
        }
    }    
}

export default mutations